package com.mantbox.channelcall.controller;

import com.mantbox.channelcall.entity.SysUser;
import com.mantbox.channelcall.utils.ResResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.mantbox.channelcall.service.SysService;
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    SysService sysService;

    @PostMapping("/login")
    public ResResult login(@RequestBody SysUser user) {
        if (!StringUtils.hasLength(user.getAccount()) || !StringUtils.hasLength(user.getPassword())) {
            return ResResult.isError("请输入账号和密码");
        }
        SysUser sysUser = sysService.selectUserByAccount(user.getAccount());
        if (sysUser == null) {
            return ResResult.isError("账号不存在");
        }
        if (sysUser.getUseable() != null && sysUser.getUseable().equals("0")) {
            return ResResult.isError("账号被禁用");
        }
        if (user.getPassword().equals(sysUser.getPassword())) {
            return ResResult.isOk("恭喜登录成功",user.getId());
        }
        return ResResult.isError("密码错误");
    }
}
